﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Edge.Common.ComponentModel;
using Edge.Common.Services;

namespace Shop.Business.Domain.Orders.Logic
{
    public class DeleteItem : BaseOrderItemOperation, IValueHolder
    {
        private bool delete = false;

        public bool Delete
        {
            get { return delete; }
            set { delete = value; }
        }

        public override void Execute(OrderController.OperationContext context)
        {
            // TODO check orderitem type

            Order order = orderItem.Order;
            DeleteVisitor deleteVisitor = new DeleteVisitor();
            deleteVisitor.Accept(orderItem);

        }

        class DeleteVisitor : IItemsVisitor
        {

            public void Accept(OrderItem item)
            {
                Order order = item.Order;
                if (order.OrderStatus == OrderStatus.Current)
                {
                    item.PriceItem.Qty += item.Quantity;
                }
                order.Items.Remove(item);
            }

        }

        public override IRestriction GetRestriction()
        {
            return null;
        }

        #region IValueHolder Members

        public object Value
        {
            get { return Delete; }
            set { this.delete = (bool)value; }
        }

        #endregion
    }
}
